<?php

namespace Hdphim\Modules\Admin\Forms\National;

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Submit;
use Phalcon\Forms\Element\Check;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Identical;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\Confirmation;

class FormCreateNational extends Form
{
	public function initialize($entity = null, $options = null)
    {
        $name = new Text('name');
        $name->setLabel('Quốc Gia');
        $name->setAttributes(array(
           // 'ng-model' => 'national.name',
            'class' => 'form-control col-xs-12', 
            'placeholder' => 'Quốc gia' 
        ));
        $name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Tên không được rỗng'
            ))
        ));

        $this->add($name);
        // CSRF
        $csrf = new Hidden('csrf');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
        )));

        $this->add($csrf);

        // Sign Up
        $this->add(new Submit('Add', array(
            'class' => 'btn btn-primary'
        )));
    }

    public function messages($name)
    {
        if($this->getMessagesFor($name))
        {
            foreach ($this->getMessagesFor($name) as $message)
            {
                $this->flash->error($message);
            }
        }
    }
      
}